using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using UnityEngine;
using Cinemachine;

public class GameManager : singleTon<GameManager>
{ 
    public CharacterStats playerStats;
    public CinemachineFreeLook freeLookCamera;

    public GameObject saber;

    public GameObject archer;

    public GameObject mage;

    public bool isEnd;

    public MoneyData_SO moneyData;
    protected override void Awake()
    {
        base.Awake();
        DontDestroyOnLoad(this);
    }

    


    public void RigisterPlayer(CharacterStats player)
    {
        playerStats = player;

        freeLookCamera = FindObjectOfType<CinemachineFreeLook>();
        if (freeLookCamera != null)
        {
            freeLookCamera.Follow = playerStats.transform;
            freeLookCamera.LookAt = playerStats.transform;
        }
    }

    List<IEndGameObserver> EndGameObservers = new List<IEndGameObserver>();

    public void AddObverser(IEndGameObserver endGameObserver)
    {
        EndGameObservers.Add(endGameObserver);
    }

    public void RemoveObverser(IEndGameObserver endGameObserver)
    {
        EndGameObservers.Remove(endGameObserver);
    }

    public void NotifyObersever()
    {
        foreach (var observer in EndGameObservers)
        {
            observer.EndNotify();
        }
    }

    public Transform GetEntrance()
    {
        foreach(var entrance in FindObjectsOfType<TransitionDestination>())
        {
            if (entrance.destinationTag == TransitionDestination.DestinationTag.Enter)
            {
                return entrance.transform;
            }
        }
        return null;
    }
}
